package lucid.hrms.management.race;

import org.apache.commons.lang.StringUtils;
import org.codehaus.grepo.query.commons.aop.QueryMethodParameterInfo;
import org.codehaus.grepo.query.hibernate.generator.CriteriaGenerator;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

public class RaceCriteriaGenerator implements CriteriaGenerator {
	public DetachedCriteria generate(QueryMethodParameterInfo qmpi) {
		RaceCriteria raceCriteria = qmpi.getParameterByParamName(
				"raceCriteria", RaceCriteria.class);
		DetachedCriteria criteria = DetachedCriteria.forClass(Race.class);

		String name = raceCriteria.getName();
		if (StringUtils.isNotEmpty(name)) {
			criteria.add(Restrictions.like("name", name + '%'));
		}

		return criteria;
	}
}